﻿using MyCompanyName.AbpZeroTemplate.Prm.Document;
using MyCompanyName.AbpZeroTemplate.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace MyCompanyName.AbpZeroTemplate.Web.Areas.Prm.Controllers
{
    public class DocumentController : AbpZeroTemplateControllerBase
    {
        private readonly IDocumentAppService _docService;

        public DocumentController(IDocumentAppService docService)
        {
            _docService = docService;
        }

        // GET: Prm/Document
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult UploadFile()
        {

            var file = Request.Files[0];
            var res = _docService.UploadFile(file);
            return Json(res, "text/html");
        }

        public async Task<ActionResult> UploadDocuments(string typeId, string projectId, string StepName)
        {
            var file = Request.Files;
            int fileCount = file.Count;
            for (int i = 0; i < fileCount; i++)
            {
                await _docService._UploadDowumnets(file[i], typeId, projectId, StepName);
            }
            return Json(new { success = true, data = "" }, "text/html");
        }

        //_UploadDocument(string typeId, string projectId, string fileName, string taskId, string reportDate, string note, HttpPostedFile file, long userId, HttpPostedFileBase uploadFile);

        public async Task<ActionResult> UploadDocument(string typeId, string projectId, string fileName, string taskId, string reportDate, string note)
        {
            var file = Request.Files[0]; 
            await _docService._UploadDocument(typeId, projectId, fileName, taskId, reportDate, note, file); 
            return Json(new { success = true, data = "" }, "text/html");
        }


        public async Task<ActionResult> UploadAttachment(string projectId, string fileName, string note, string tags)
        {
            var file = Request.Files[0];
            await _docService._UploadAttachment(projectId, fileName, note, file, tags);
            return Json(new { success = true, data = "" }, "text/html");
        }
    }
}